package top.hjcwzx.wrench.design.framework.tree;


public abstract class AbstractStrategyRouter<T, D, R> implements StrategyMapper<T, D, R>, StrategyHandler<T, D, R> {

    public StrategyHandler<T, D, R> defaultStrategyHandler = StrategyHandler.DEFAULT;

    public R router(T requestParam, D dynamicContext) throws Exception {
        StrategyHandler<T, D, R> tdrStrategyHandler = get(requestParam, dynamicContext);
        if (null == tdrStrategyHandler) {
            return defaultStrategyHandler.apply(requestParam, dynamicContext);
        }
        return tdrStrategyHandler.apply(requestParam, dynamicContext);
    }

}
